package leetCode.firstWeek;

import java.util.LinkedList;
import java.util.List;

public class Code_22 {
    List<String> res = new LinkedList<>();

    public List<String> generateParenthesis(int n) {
        recursion(n, n, "");
        return res;
    }

    public void recursion(int left, int right, String mid) {
        if (left == 0 && right == 0) {
            res.add(mid);
            return;
        }
        if (left > 0) {
            recursion(left - 1, right, mid + "(");
        }
        if (right > left) {
            recursion(left, right - 1, mid + ")");
        }
    }
}
